<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>邀请团队成员</title>
    <link rel="stylesheet" href="./layui/css/layui.css">
</head>
<style>
    .mxnW{
        width: 80%;
        margin: 0 auto;
        margin-top: 20px;
    }
    .hidden{
        display: none;
    }
</style>
<body>
<!--//加入团队-->
<form class="layui-form mxnW " id="add" >
    <div class="layui-form-item">
        <label class="layui-form-label">团队镖旗</label>
        <div class="layui-input-block">
            <img id="setImg" style="width: 60px;height: auto" src="" alt="">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">团队名称</label>
        <div class="layui-input-block">
            <input type="text" disabled name="title" required  lay-verify="required" placeholder="请输入团队名称" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">简介</label>
        <div class="layui-input-block">
            <textarea name="info" disabled placeholder="请输入简介内容" class="layui-textarea"></textarea>
            <button style="margin-top: 10px"  class="layui-btn" lay-submit lay-filter="formDemo">立即加入</button>

        </div>
    </div>

</form>
<script src="../../public/js/jquery.min.js"></script>
<script>
    $.ajax({
        type: 'POST',
        url:"/team/search",
        data: {data:{key:'userid',value:JSON.parse(sessionStorage.user).userid}},
        success:function (data) {
            console.log(data)
            for(var i=0;i<data.result.length;i++){
                $("#teamToProject").append(
                    '<option value='+data.result[i].teamid+'>'+data.result[i].title+'</option>'
                )
                $("#teamToSelect").append(
                    '<option value='+data.result[i].teamid+'>'+data.result[i].title+'</option>'
                )
            }
        } ,
        error:function () {
            layer.msg("系统错误")
        }
    })

</script>
<script src="./layui/layui.js"></script>
<script>
    //Demo
    var tpl={
        data:{},
        setData:function () {
            $("#setImg").attr("src",this.data.picture||"../../img/team.png");
            $("input[name='title']").val(this.data.title||"");
            $("textarea[name='info']").val(this.data.info||"");
        },
        getData:function () {
            return {
            }
        }
    }
    var id = location.href.split("?")[1];
    //请求数据
    $.ajax({
        type: 'POST',
        url:"/team/detail",
        data: {data:{teamid:id}},
        success:function (data) {
            tpl.data = data.result;
            tpl.setData();
        } ,
        error:function () {
            layer.msg("系统错误")
        }
    })
    layui.use('form', function(tpl){
        var form = layui.form();
        //监听提交
        form.on('submit(formDemo)', function(data){
            if(sessionStorage.hasOwnProperty("user")){
                sessionStorage.setItem("userTemp",sessionStorage.user);
            }
            layer.open({
                type: 2,
                title: '选择设置团队',
                shadeClose: true,
                shade: 1,
                area: ['70%', '90%'],
                content: location.origin+"/webpack/src/pages/layer/loginAuth.html",
                end:function () {
                    //判断是否存在该用户

                    $.ajax({
                        type: 'POST',
                        url:"/userProject/create",
                        data: {data:{teamid:location.href.split("?")[1],userid:JSON.parse(sessionStorage.user).userid}},
                        success:function (data) {
                            if(data.msg.type==1){
                                layer.msg(data.msg.data);
                            }
                        } ,
                        error:function () {
                            layer.msg("系统错误")
                        }
                    })
                    if(sessionStorage.hasOwnProperty("userTemp")){
                        sessionStorage.user=sessionStorage.userTemp;
                    }
                }
            });
            return false;
        });
    });
    layui.use('upload', function(){
        layui.upload({
            url: '/ueditor/ue?action=uploadimage'
            ,success: function(res){
                console.log(res); //上传成功返回值，必须为json格式
                if(res.state=="SUCCESS"){
                    layer.msg('上传成功')
                    $("#setImg").attr("src",location.origin+res.url)
                }else{
                    layer.msg('上传失败')
                }
            }
        });
    });
</script>
</body>
</html>